(()=> {
	let ele = {};
	ele.look = $('#look');
	ele.modal_gold = $('#modal-gold');
	ele.close_gold = $('#close-gold');
	ele.riqi = $('#riqi');
	ele.list = $('#list');
	ele.listBox = $('#listBox');
	ele.empty = $('#empty');
	ele.more = $('#more');
	
	//打开 入围名单
	// ele.look.onclick = () => {
	// 	openMdl(ele.modal_gold);
	// }
	//关闭 入围名单
	ele.close_gold.onclick = () => {
		closeMdl(ele.modal_gold);
	}
	
	let ring_id = ''
	let page = 1;
	
	getFinaListRecordsList(page)
	// 获取入围记录 列表
	function getFinaListRecordsList(page) {
		let token = getCookie("token");
		ajax({
			url: API_PATH.GET_FINALIST_RECORDS_LIST,
			method: 'get',
			header: {
				'Authorization': token,
			},
			data: {
				page: page
			},
			success: res => {
				if (res.code == 1) {
					let detail = res.data.list.data;
					if (detail.length === 0) {
						page = 0;
						ele.more.style.display = "none";
						ele.empty.style.display = "flex";
					} else {
						drawDetail(detail);
						page++;
						if (page > res.data.list.last_page) {
							ele.more.innerText = '没有更多了';
							ele.more.onclick = null;
						}
						else {
							ele.more.innerText = '加载更多';
							ele.more.onclick = () => getFinaListRecordsList(page);
						}
					}
					// for(let i = 0; i < _data.length; i++) {
					// 	if(_data[i].status == 1) {
					// 		ring_id = _data[i].id
					// 		// ele.riqi.innerHTML = _data[i].phase
					// 		getFinaListRecords(ring_id)
					// 	}
					// }
				} else openTips(res.msg || '未知错误');
			}
		});
	}
	
	function drawDetail(data) {
		if (data.length === 0) {
			page = 0;
			ele.more.style.display = "none";
			ele.empty.style.display = "flex";
		} else {
			let str = '';
			for (let i = 0; i < data.length; i++) {
				let resume = data[i].remark;
				let sign = data[i].status == 1 ? '<span>本期</span>' : '';
				str +=`<div class="list">
							${sign}
							<p>${data[i].phase}</p>
							<button onclick="getFinaListRecords(${data[i].id},${data[i].status})">查看名单</button>
						</div>`;
			}
			ele.listBox.innerHTML += str;
		}
	}
	
	// window.chakan = function chakan(id) {
		
	// }
	
	// 获取入围记录
	window.getFinaListRecords = function getFinaListRecords(id,is_status) {
		let token = getCookie("token");
		ajax({
			url: API_PATH.GET_FINALIST_RECORDS,
			method: 'post',
			header: {
				'Authorization': token,
			},
			data: {
				ring_id: id
			},
			success: res => {
				if (res.code == 1) {
					drawList(res.data.list,is_status)
				} else openTips(res.msg || '未知错误');
			}
		});
	}
	
	function drawList(data,is_status) {
		let html = '';
		let headerimg = ''
		let pai = ''
		let is_bq = ''
		for(let i = 0; i < data.length; i++) {
			let j = i + 1;
			if(data[i].head_pic == '' || data[i].head_pic == null) {
			    if(data[i].sex == 1) {
			        headerimg = 'http://img.qxgs.cc/tiantianlaishouzu/img/my/tx1.png'
			    }else {
			        headerimg = 'http://img.qxgs.cc/tiantianlaishouzu/img/my/tx2.png'
			    }
			}else {
			    headerimg = IMG_DOMAIN + data[i].head_pic
			}
			is_bq = is_status == 1 ? '<span class="benqi">本期</span>' : ''
			pai = i == 0 ? '<img class="rankimg" src="http://img.qxgs.cc/tiantianlaishouzu/img/rank/1.png" alt="">' : i== 1 ? '<img class="rankimg" src="http://img.qxgs.cc/tiantianlaishouzu/img/rank/2.png" alt="">' : i == 2 ? '<img class="rankimg" src="http://img.qxgs.cc/tiantianlaishouzu/img/rank/3.png" alt="">' : '<p class="rankimg">'+j+'</p>'
			html += `<div class="item">
						${is_bq}
						<div class="left">
							${pai}
							<img class="tximg" src="${headerimg}" alt="">
							<div class="itemin">
								<p class="mobile">我叫大王</p>
								<p class="time">房间人数<span>35/40</span></p>
							</div>
						</div>
						<div class="right">
							<p>房产名字编号:<span>45</span> </p>
							<p>团队豪华值:<span>4565</span> </p>
						</div>
					</div>`
		}
		ele.list.innerHTML = html;
		openMdl(ele.modal_gold);
	}
})()